package com.payment.ktb.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.payment.ktb.R;
import com.payment.ktb.model.InviteRecordEntity;
import com.payment.ktb.view.RoundRecImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by admin on 2017/9/4.
 */

public class InviteRecordAdapter extends BaseAdapter {

    private Context context;
    private List<InviteRecordEntity> listDates;


    public InviteRecordAdapter(Context context, List<InviteRecordEntity> listDates) {
        this.context = context;
        this.listDates = listDates;
    }

    public InviteRecordAdapter() {

    }

    @Override
    public int getCount() {
        return listDates.size();
    }

    @Override
    public Object getItem(int i) {
        return listDates.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;
        if (view == null){
            viewHolder = new ViewHolder();
            view = View.inflate(context, R.layout.adapter_inviterecord_item,null);
            viewHolder.iv_inviterecord_portrait = (RoundRecImageView) view.findViewById(R.id.iv_inviterecord_portrait);
            viewHolder.tv_inviterecord_username = (TextView) view.findViewById(R.id.tv_inviterecord_username);
            viewHolder.tv_inviterecord_phone = (TextView) view.findViewById(R.id.tv_inviterecord_phone);
            viewHolder.tv_inviterecord_statusName = (TextView) view.findViewById(R.id.tv_inviterecord_statusName);
            viewHolder.iv_inviterecord_coupon = (ImageView) view.findViewById(R.id.iv_inviterecord_coupon);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.tv_inviterecord_username.setText(listDates.get(i).getUserNick());

        viewHolder.tv_inviterecord_phone.setText(listDates.get(i).getUserPhone());

        if (listDates.get(i).getIsOver() == 0) {
            viewHolder.tv_inviterecord_statusName.setText("待完成");
            viewHolder.tv_inviterecord_statusName.setTextColor(context.getResources().getColor(R.color.blue));
        }else {
            viewHolder.tv_inviterecord_statusName.setText("已完成");
            viewHolder.tv_inviterecord_statusName.setTextColor(context.getResources().getColor(R.color.green));
        }

        if (listDates.get(i).getIsCharge() == 0) {
            viewHolder.iv_inviterecord_coupon.setVisibility(View.GONE);
        }else {
            viewHolder.iv_inviterecord_coupon.setVisibility(View.VISIBLE);
        }

        if (!TextUtils.isEmpty(listDates.get(i).getPicHeader()) && listDates.get(i).getPicHeader().contains("http") ) {
            Picasso.with(context).load(listDates.get(i).getPicHeader()).fit().error(R.mipmap.my_head_portrait).into(viewHolder.iv_inviterecord_portrait);
        }

        return view;
    }



    class ViewHolder{
        RoundRecImageView iv_inviterecord_portrait;
        TextView tv_inviterecord_username;
        TextView tv_inviterecord_phone;
        ImageView iv_inviterecord_coupon;
        TextView tv_inviterecord_statusName;
    }

}
